package com.terrynoya.fight.animations.movieClip
{
	import com.terrynoya.fight.animations.Animation;
	import com.terrynoya.fight.animations.Clsn;
	import com.terrynoya.fight.animations.IAnimation;
	import com.terrynoya.fight.animations.IAnimationElement;
	import com.terrynoya.fight.combat.Collisions;
	import com.terrynoya.fight.emuns.ClsnType;
	
	import flash.display.MovieClip;
	import flash.geom.Rectangle;

	public class MCAnimation extends Animation
	{
		private var _data:Array = [
			"-13, -79, 16, 0",
			"-7, -93, 5, -79"
		];
		
		public function MCAnimation(id:int,mc:MovieClip,loopStart:int = 0)
		{
			super(id,loopStart,this.getElements(mc));
		}
		
		private function getElements(mc:MovieClip):Array
		{
			var rlt:Array = new Array();
			var totalFrames:int = mc.totalFrames;
			for (var i:int = 0; i < totalFrames; i++) 
			{
				var ele:MCAniElement = new MCAniElement();
				ele.id = i;
				ele.ticks = 1;
				ele.clsns = this.defaultClsns();
				rlt.push(ele);
			}
			return rlt;
		}
		
		private function defaultClsns():Array
		{
			var arr:Array = new Array();
			for (var i:int = 0; i < this._data.length; i++) 
			{
				var value:String = this._data[i];
				arr.push(this.parseRectInfo(value));
			}
			return arr;
		}
		
		private function parseRectInfo(value:String):Clsn
		{
			var clsn:Clsn = new Clsn(ClsnType.Type2Normal);
			var arr:Array = value.split(",");
			var lx:Number = arr[0];
			var ly:Number = arr[1];
			var bx:Number = arr[2];
			var by:Number = arr[3];
			var width:Number = bx - lx;
			var height:Number = by - ly;
			clsn.rect = new Rectangle(lx,ly,width,height); 
			return clsn;
		}
	}
}